
public class Originator {

	 private String state;
	 
	 public void set(String state) {
	  this.state=state; 
	  System.out.println("Originator: State set to" + state); 
	 } 
	
	 public Object saveToMemento() {
	  return new Memento(state);
	 }
	
	 public void restoreFromMemento(Object o) {
	  if(o instanceof Memento) {
	   Memento m=(Memento)o;
	   state=m.getSavedState();
	   System.out.println("Originator:Just restored from Memento to State:" + state);
	  }
	 }
}
